package com.google.android.exoplayer2.scheduler;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.os.PowerManager;
import com.huawei.updatesdk.service.otaupdate.UpdateKey;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import o.anr;

public final class Requirements {
    private static final String[] ˎ = null;
    private final int ˊ;

    @Documented
    @Retention(RetentionPolicy.SOURCE)
    public @interface NetworkType {
    }

    public Requirements(int i, boolean z, boolean z2) {
        int i2;
        int i3 = 0;
        if (z) {
            i2 = 16;
        } else {
            i2 = 0;
        }
        i2 |= i;
        if (z2) {
            i3 = 8;
        }
        this(i3 | i2);
    }

    public Requirements(int i) {
        this.ˊ = i;
    }

    public int ˋ() {
        return this.ˊ & 7;
    }

    public boolean ॱ() {
        return (this.ˊ & 16) != 0;
    }

    public boolean ˊ() {
        return (this.ˊ & 8) != 0;
    }

    public boolean ॱ(Context context) {
        return ˎ(context) && ˋ(context) && ˊ(context);
    }

    public int ˏ() {
        return this.ˊ;
    }

    private boolean ˎ(Context context) {
        int ˋ = ˋ();
        if (ˋ == 0) {
            return true;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
            ˎ("No network info or no connection.");
            return false;
        } else if (!ˋ(connectivityManager)) {
            return false;
        } else {
            if (ˋ == 1) {
                return true;
            }
            boolean isRoaming;
            if (ˋ == 3) {
                isRoaming = activeNetworkInfo.isRoaming();
                ˎ("Roaming: " + isRoaming);
                return !isRoaming;
            }
            isRoaming = ˋ(connectivityManager, activeNetworkInfo);
            ˎ("Metered network: " + isRoaming);
            if (ˋ == 2) {
                if (isRoaming) {
                    return false;
                }
                return true;
            } else if (ˋ == 4) {
                return isRoaming;
            } else {
                throw new IllegalStateException();
            }
        }
    }

    private boolean ˋ(Context context) {
        if (!ॱ()) {
            return true;
        }
        Intent registerReceiver = context.registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
        if (registerReceiver == null) {
            return false;
        }
        int intExtra = registerReceiver.getIntExtra(UpdateKey.STATUS, -1);
        if (intExtra == 2 || intExtra == 5) {
            return true;
        }
        return false;
    }

    private boolean ˊ(Context context) {
        if (!ˊ()) {
            return true;
        }
        PowerManager powerManager = (PowerManager) context.getSystemService("power");
        boolean isDeviceIdleMode = anr.ˋ >= 23 ? powerManager.isDeviceIdleMode() : anr.ˋ >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn();
        return isDeviceIdleMode;
    }

    private static boolean ˋ(ConnectivityManager connectivityManager) {
        if (anr.ˋ < 23) {
            return true;
        }
        Network activeNetwork = connectivityManager.getActiveNetwork();
        if (activeNetwork == null) {
            ˎ("No active network.");
            return false;
        }
        boolean z;
        NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork);
        if (networkCapabilities == null || !networkCapabilities.hasCapability(16)) {
            z = true;
        } else {
            z = false;
        }
        ˎ("Network capability validated: " + z);
        if (z) {
            return false;
        }
        return true;
    }

    private static boolean ˋ(ConnectivityManager connectivityManager, NetworkInfo networkInfo) {
        if (anr.ˋ >= 16) {
            return connectivityManager.isActiveNetworkMetered();
        }
        int type = networkInfo.getType();
        if (type == 1 || type == 7 || type == 9) {
            return false;
        }
        return true;
    }

    private static void ˎ(String str) {
    }

    public String toString() {
        return super.toString();
    }
}
